package com.juyu.miliao.api.util;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;

public class LocalDateTimeUtil {
	/**
	 * 获取每周2日期
	 * @return
	 */
	public static String getTuesdayDate() {
		LocalDateTime now = LocalDateTime.now();// 取当前日期
		DateTimeFormatter dtf = DateTimeFormatter.ISO_DATE;
		switch (now.getDayOfWeek().getValue()) {
			case 2:
				return now.format(dtf);
			case 3:
				return now.minusDays(1).format(dtf);
			case 4:
				return now.minusDays(2).format(dtf);
			case 5:
				return now.minusDays(3).format(dtf);
			case 6:
				return now.minusDays(4).format(dtf);
			case 7:
				return now.minusDays(5).format(dtf);
			case 1:
				return now.minusDays(6).format(dtf);
		}
		return "";
	}

	/**
	 * 时间戳毫秒转LocalDate
	 *
	 * @param timestamp
	 * @return
	 */
	public static LocalDate milliTime2LocalDate(long timestamp) {
		LocalDateTime dateTime = LocalDateTime.ofEpochSecond(timestamp / 1000, 0, ZoneOffset.ofHours(8));
		return dateTime.toLocalDate();
	}

	/**
	 * 获取今天开始时间13位时间戳
	 *
	 * @return
	 */
	public static long getLocaDateBegin() {
		LocalDateTime beginTime = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
		return beginTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();
	}
}
